import vue from "vue";
import App from "@/app.vue";
import vueRouter from "vue-router";

vue.use(vueRouter);

const _import = (path: string) => () => import(`@view/${path}`);

export default new vueRouter({
  // mode:'history',
  routes: [
    {
      path: "*",
      name: "pageNotFound",
      component: _import("404.vue"),
    },
    {
      path: "/",
      component: App,
      redirect: "main",
      children: [
        {
          path: "main",
          name: "main",
          component: _import("main/index.vue"),
        },
        // demo实例
        {
          path: "demo",
          name: "demo",
          component: _import("demo/index.vue"),
        },
      ],
    },
  ],
});
// router.onError((error) => {
//     const pattern = /Loading chunk (\d)+ failed/g;
//     const isChunkLoadFailed = error.message.match(pattern);
//     const targetPath = router.history.pending.fullPath;
//     if(isChunkLoadFailed){
//         router.replace(targetPath);
//     }
// })
//
// export default router
